package com.smbe.netty.httpdemo;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.*;
import io.netty.util.CharsetUtil;

/**
 * <p>Title: </p>
 * <p>Company:misspao </p>
 *
 * @author: buwenmin
 * @Date: Create in 22:00 2019/1/23
 * @Description:
 */
public class TestHttpServerHandler extends SimpleChannelInboundHandler<HttpObject> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
        ByteBuf buffer = Unpooled.copiedBuffer("Hello NETTY", CharsetUtil.UTF_8);

        FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buffer);
        response.headers().set(HttpHeaderNames.CONTENT_TYPE ,"text/plain");
        response.headers().set(HttpHeaderNames.CONTENT_LENGTH,buffer.readableBytes());

        ctx.writeAndFlush(response);


    }
}
